<html>
<head><meta charset="utf-8"><title>Muckable Pitfall - Newtype Workaround Ergonomics · project-safe-transmute · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/index.html">project-safe-transmute</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html">Muckable Pitfall - Newtype Workaround Ergonomics</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218320527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218320527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218320527">(Nov 30 2020 at 17:46)</a>:</h4>
<p>Just because you <em>can</em> newtype your way out of some holes <a href="#narrow/stream/216762-project-safe-transmute/topic/Incremental.20Approach/near/218253083">doesn't mean that's a satisfactory solution</a>, as <span class="user-mention" data-user-id="209168">@Thom Chiovoloni</span> observes. The places where safe transmutation will have the biggest impact is on modules that are currently rife with unsafe code. Asking end-users to totally refactor the innards of their unsafe types is <em>asking</em> for user-error.</p>
<p>The right thing to do should be the easy thing to do.</p>



<a name="218325401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218325401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218325401">(Nov 30 2020 at 18:26)</a>:</h4>
<p>What makes the newtype pattern a total refactor? It should only really affect the edges of the module. Do you have some specific scenarios in mind where you can't see a way to avoid more invasive changes? And are those scenarios really worth the costs of having <code>Scope</code> in the API forever?</p>



<a name="218328391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218328391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218328391">(Nov 30 2020 at 18:49)</a>:</h4>
<p>You'll need to adjust all of your field accesses. How complex of a refactor this is depends on how much you manipulate fields directly, and the visibility of those fields.</p>



<a name="218328576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218328576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218328576">(Nov 30 2020 at 18:50)</a>:</h4>
<p>The existence of a scope-aware foundational API doesn't preclude the existence of a scope-unaware <code>Muckable</code> abstraction. If you think the cognitive cost of <code>Scope</code> is higher than <code>Muckable</code>, you simply don't have to pay it — you can just use <code>Muckable</code> instead.</p>



<a name="218329971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218329971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218329971">(Nov 30 2020 at 19:00)</a>:</h4>
<p>That's not how costs work at this level. If <code>Scope</code> exists in the API, people will use it, and thus people will encounter it. We've long established that <code>Scope</code> is a totally new idiom for a situation that the existing ecosystem handles differently, so its mere existence expands the set of idioms people will need to deal with.</p>



<a name="218330215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218330215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218330215">(Nov 30 2020 at 19:02)</a>:</h4>
<p>Field access through newtypes, on the other hand, has been around for a long time. You can mitigate the amount of change by some additional boilerplate (e.g. delegation from newtype methods to existing, now-internal methods) or by judiciously inserting <code>.0</code> or <code>Newtype(inner)</code> syntax in various places.</p>



<a name="218330484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218330484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218330484">(Nov 30 2020 at 19:04)</a>:</h4>
<p>So again: do you have any more specific scenarios in mind? I'm well aware that "use the existing boilerplate-y idioms" is not perfect, but I'm weighing that against the cost of an entirely new idiom that everyone involved keeps saying might/should go away in the future!</p>



<a name="218330598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218330598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218330598">(Nov 30 2020 at 19:05)</a>:</h4>
<p>I totally expect people will use the foundational API. I also totally expect people (especially library authors) will also use the stability-unaware API that connotes SemVer stability.</p>



<a name="218330789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218330789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218330789">(Nov 30 2020 at 19:07)</a>:</h4>
<p>And yes, I do have other scenarios in mind. I'm going to continue to create topics for each scenario that I recall having been raised up till now.</p>



<a name="218330847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218330847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218330847">(Nov 30 2020 at 19:07)</a>:</h4>
<p>The topics you've created so far are not addressing my question...</p>



<a name="218331105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218331105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218331105">(Nov 30 2020 at 19:09)</a>:</h4>
<p>Well, I hope I manage to address it with one of these topics by the time I finish. Failing that, I hope to convince at least a subset of "everyone involved" that <code>Scope</code> isn't a boogeyman. (And no, not "everyone involved" thinks <code>Scope</code> shouldn't exist...)</p>



<a name="218331270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218331270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218331270">(Nov 30 2020 at 19:10)</a>:</h4>
<p>Safe transmutation based on compiler-supported layout reflection is, itself, a new idiom. I hope to demonstrate that <code>Scope</code> parameter is a good complement to it.</p>



<a name="218331653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Muckable%20Pitfall%20-%20Newtype%20Workaround%20Ergonomics/near/218331653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Muckable.20Pitfall.20-.20Newtype.20Workaround.20Ergonomics.html#218331653">(Nov 30 2020 at 19:13)</a>:</h4>
<p>Anyways, yes: the newtype pattern is well-established. However, using field visibility to achieve encapsulation is <em>also</em> an established idiom. And field visibility is <em>precisely</em> what separates a safe transmutation from one that's merely well-defined.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>